<%@page import="com.egame.manage.biz.server.gc.GameServiceImpl"%>
<%@page import="cn.egame.interfaces.EnumType.FileStatus"%>
<%@page import="cn.egame.interfaces.EnumType.GameStatus"%>
<%@page import="java.util.Date"%>
<%@page import="java.text.DateFormat"%>
<%@page import="java.text.SimpleDateFormat"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%@page import="java.util.List"%>
<%@page import="cn.egame.interfaces.gc.GameFileInfo"%>    
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link type="text/css" rel="stylesheet" href="<%=request.getContextPath()%>/css/main.css"  />
<script type="text/javascript" src="<%=request.getContextPath()%>/js/jquery-1.4.2.min.js"></script>
<script type="text/javascript" src="<%=request.getContextPath()%>/js/common.js"></script>
<title>游戏实体列表</title>
</head>
<body>
<script type="text/javascript">
	Date.prototype.format = function(format) {
	    /*
	     * eg:format="YYYY-MM-dd hh:mm:ss";
	     */
	    var o = {
	        "M+" :this.getMonth() + 1, // month
	        "d+" :this.getDate(), // day
	        "h+" :this.getHours(), // hour
	        "m+" :this.getMinutes(), // minute
	        "s+" :this.getSeconds(), // second
	        "q+" :Math.floor((this.getMonth() + 3) / 3), // quarter
	        "S" :this.getMilliseconds()
	    }
	    if (/(y+)/.test(format)) {
	        format = format.replace(RegExp.$1, (this.getFullYear() + "")
	                .substr(4 - RegExp.$1.length));
	    }
	    for ( var k in o) {
	        if (new RegExp("(" + k + ")").test(format)) {
	            format = format.replace(RegExp.$1, RegExp.$1.length == 1 ? o[k]
	                    : ("00" + o[k]).substr(("" + o[k]).length));
	        }
	    }
	    return format;
	};

	function adapt(fid,gid){
		var myform = document.getElementById("addform");
		document.getElementById("gameId").value=gid;
		document.getElementById("fileId").value=fid;
		myform.action = "<%=request.getContextPath()%>" + "/tv/game/file/terminal/adapt/show.do";
		myform.submit();
	}

	function showDetail(fid,gid){
		$.ajax({			
			url : "<%=request.getContextPath() + "/tv/game/file/fileinfo.do" %>",
			type : 'post',
			data : {
				'fileid' : fid,
				'gid':gid
			},
			success : function(data) {	
				$("#fileInfo td.fileName").html(data.fileName);
				$("#fileInfo td textarea.remark").text(data.remark);
				$("#fileInfo td.packageName").html(data.packageName);
				$("#fileInfo td.versionName").html(data.versionName);
				$("#fileInfo td.versionCode").html(data.versionCode);
				$("#fileInfo td.status").html(data.fileStatus);
				var historyDate = new Date(data.insertTime).format("yyyy-MM-dd hh:mm:ss");
				$("#fileInfo td.subTime").html(historyDate);
				$("#gameId").val(data.gId);
				$("#fileId").val(data.fileId);
				setDialog('fileInfo');
			}
		});		
	}
</script>
<form action="" id="myform">	
	<div class="matter_box">
		<h3 class="nopoint"><strong>游戏实体列表</strong></h3>
			<table cellpadding="0" cellspacing="0" class="table2" id="rights_list">
				<tr class="first">
					<th>序号</th>
					<th>实体名称</th>
					<th>包名</th>
					<th>版本名称</th>
					<th>版本编号</th>
					<th>提交时间</th>
					<th>实体状态</th>
					<th>操作</th>	
				</tr>
	<%
	if(request.getAttribute("list")!=null){
		List<GameFileInfo> list = (List<GameFileInfo>)request.getAttribute("list");
		int i=1;
		for(GameFileInfo bean:list){
			%>
			<tr>
				<td><%=i++ %> </td>
				<td>
					<a href="javascript:showDetail(<%=bean.getFileId() %>,<%=bean.getgId() %>)"><%=bean.getFileName() %></a>					 
				</td>
				<td><%=bean.getPackageName() %> </td>
				<td><%=bean.getVersionName() %> </td>
				<td><%=bean.getVersionCode() %> </td>
				<td>
					<%
						String insertTime = "";
						if(bean.getInsertTime()>0){
							insertTime = cn.egame.common.util.Utils.toDateString(bean.getInsertTime(),"yyyy-MM-dd hh:mm:ss");
						}
					%>
					<%=insertTime %> 
				</td>
				
				<td><%=(bean.getFileStatus()).getMessage() %></td>
				<td>
				<% 
					int gid = 0;
					if(request.getAttribute("gid")!=null){
						gid = (Integer) request.getAttribute("gid");
					}
					String changeFileStatusUrl = request.getContextPath() + "/tv/game/file/status/change.do?"
							+ "gid=" + gid
							+ "&fileid=" + bean.getFileId()
							+ "&filestatus=" + ""; 
				%>
					<% if(bean.getFileStatus() == FileStatus.none){ %>
						<a href="<%=changeFileStatusUrl + FileStatus.testPassed.value() %>">测试通过</a>
						<a href="<%=changeFileStatusUrl + FileStatus.testNotPassed.value() %>">测试不通过</a>
					<% }else if(bean.getFileStatus() == FileStatus.testPassed){ %>
						<a href="<%=changeFileStatusUrl + FileStatus.testNotPassed.value() %>">测试不通过</a>
						<a href="javascript:adapt(<%=bean.getFileId() %>,<%=bean.getgId() %>)">适配机型</a>
					<% }else if(bean.getFileStatus() == FileStatus.testNotPassed){ %>
						<a href="<%=changeFileStatusUrl + FileStatus.testPassed.value() %>">测试通过</a>
					<% }else if(bean.getFileStatus() == FileStatus.adaptationed){ %>
						<a href="javascript:adapt(<%=bean.getFileId() %>,<%=bean.getgId() %>)">适配机型</a>
					<% } %>
					<a href="<%=request.getContextPath() + "/tv/game/file/delete.do?id=" + bean.getFileId() + "&gid=" + gid %>">删除</a>
					<a href="<%=GameServiceImpl.getInstance().getImagePath(0, 0L, bean.getEFSId()) %>">下载</a>
				</td>
			</tr>
			<%
		}				
	}
	%>
</table>
</div>
</form>
<div class="dialog_table editor_group" id="fileInfo" style="width:400px">
	<h2 class="tc">实体信息</h2>
	<form action="<%=request.getContextPath() + "/tv/game/file/set/remark.do"%>" method="post" id="addform">
	
		<input type=hidden name=gid value=<%=0 %> id="gameId">
		<input type=hidden name=fileid value=<%=0 %> id="fileId">
			<table>
				<tr>
					<td align="right">文件名称:</td>
					<td class="pl25 fileName"></td>
				</tr>
				<tr>
					<td align="right">文件说明:</td>
					<td class="pl25">
						<textarea rows="5" cols="40" name="remark" class="remark"></textarea>
					</td>
				</tr>
				<tr>
					<td align="right">包名:</td>
					<td class="pl25 packageName">
					</td>
				</tr>
				<tr>
					<td align="right">VersionName:</td>
					<td class="pl25 versionName">
					</td>
				</tr>
				
				<tr>
					<td align="right">VersionCode:</td>
					<td class="pl25 versionCode">
					</td>
				</tr>
				
				<tr>
					<td align="right">提交时间:</td>
					<td class="pl25 subTime">
					</td>
				</tr>
				
				<tr>
					<td align="right">实体状态:</td>
					<td class="pl25 status">
					</td>
				</tr>
				<tr>
					<td colspan=2 align="center">
						<input class="btn3" type="submit" value="提交">
					</td>			
				</tr>
			</table>	
	</form>
</div>
</body>
</html>